using System;
using System.Collections;
using System.Collections.Generic;
using Core.Runtime;
using Cysharp.Threading.Tasks;
using UnityEngine;

/*
 * 新的window，打包出UpdateData
 * ProjectSetting 校验设置面板
 */
namespace GameLauncher.Runtime
{
    /// <summary>
    /// 启动器
    /// </summary>
    public partial class Launcher : MonoBehaviour
    {
        private async void Start()
        {
            try
            {
                await InitCoreSystem();
                await Splash();
                await HotFix();
            }
            catch (Exception e)
            {
                mHotFixStateMachine?.Cancel();
                Debug.LogError(e.ToString());
            }
        }

        /// <summary>
        /// 初始化核心系统
        /// </summary>
        private async UniTask InitCoreSystem()
        {
            await InitAssetSystem();
        }

        /// <summary>
        /// 资源系统
        /// </summary>
        private async UniTask InitAssetSystem()
        {
            await UniTask.Yield();
            PersistentObjects.AddPersistentObject<ProfilerComponent>();
            PersistentObjects.AddPersistentObject<AssetLifecycle>();
        }

        /// <summary>
        /// 闪屏
        /// </summary>
        private async UniTask Splash()
        {
            await UniTask.Yield();
        }

        private async UniTask HotFix()
        {
            mHotFixStateMachine = new HotFixStateMachine();
            await mHotFixStateMachine.Run();
        }

        private HotFixStateMachine mHotFixStateMachine;
    }
}